package StudyCode.summary.myfile;

import java.nio.ByteBuffer;
import java.util.Arrays;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ConvertsFloatToByteLength4 {
	public static void main(String[] argv) {
		float f = 2.45678f;
		System.out.println(f + "转为长度为4的字节数组:");
		System.out.println(Arrays.toString(floatToByteArray(f)));
	}

	private static byte[] floatToByteArray(float f) {
		return ByteBuffer.allocate(4).putFloat(f).array();
	}
}
